#ifndef CHECKPROCESS_H
#define CHECKPROCESS_H

#include <QObject>
#include <QList>
#include <QThread>
#include <iostream>
#include <stdio.h>
#include <QRegExp>
#include <windows.h>
#include <tlhelp32.h>
#include <QDebug>
#include "Process.h"

class CheckProcess : public QThread
{
    Q_OBJECT
public:
    explicit CheckProcess(int refreshRate = 1000, QObject *parent = 0);
    ~CheckProcess();

    /*
     *  Function to set the refresh rate of the process scanning
     *  @param int ms : Milliseconds between each scan
     */
    void setRefreshRate(int ms);

    /*
     *  Function called by the start() function of the QThread object
     */
    void run();

    /*
     *  Function to stop the scanning thread
     */
    void stop();


    /*
     *  Function to test if a process exist depending of is process ID
     *  @param QList<Process *> * processList : list of process where to check
     *  @param Process * process : process to compare whith the list
     *  @return bool : Boolean if the process exist or not
     */
    static bool processExist(QList<Process *> * processList, Process * process);

    const static int ProcessActive = 1;
    const static int ProcessInactive = 0;
private:
    /*
     *  Function to clear the process list and delete it
     *  @param QList<Process *> * processList : list of process to delete
     */
    void deleteProcessList(QList<Process *> * processList);


    /*
     *  Function to treat the process list, check the new and the missing from the previous scan
     *  @param QList<Process *> * processList : list of process to compare with the old one
     */
    void treatProcessList(QList<Process *> * processList);

    QList<Process *> * processList;
    int refreshRate;
signals:
    void signalProcessStarted(Process *);
    void signalProcessStopped(Process *);

public slots:

};

#endif // CHECKPROCESS_H
